package com.zhiwei.common.config;

/**
 * functipn: 安全上下文，用户获取用户名
 * author: zhiwei_yang
 * time: 2020/5/5-16:48
 */
public final class SecurityContext {

    private static final ThreadLocal<String> userNameThreadLocal = new ThreadLocal<>();

    /**
     * 设置用户名
     * @param username
     */
    public static void setUsername(String username){
        userNameThreadLocal.set(username);
    }

    /**
     * 获取用户名
     */
    public static String getUsername(){
        return userNameThreadLocal.get();
    }

    /**
     * 清理用户信息
     */
    public static void clear(){
        userNameThreadLocal.remove();
    }
}
